﻿using System.Reflection;

namespace Foundation.Core
{
    public interface ITypeSelectCreateExecutor : ISelectFilterMetadata
    {
        bool CanHandle(Type type);

        IList<MemberInfo> GetMemberInfos(Type type);

        object CreateModel(Type type);

        void Execute(TypeSelectCreateExecuteContext context);
    }

    public class TypeSelectCreateExecuteContext : SelectExtend, ISelectExtend
    {
        public TypeSelectCreateExecuteContext(string key, SelectCategory category, MemberInfo memberInfo, object instance = null, IDictionary<string, object> extend = null)
        {
            Key = key;
            Category = category;
            MemberInfo = memberInfo;
            Instance = instance;

            if (extend != null)
            {
                Extend = extend;
            }
        }

        public string Key { get; }

        public SelectCategory Category { get; }

        /// <summary>
        /// 成员元数据
        /// </summary>
        public MemberInfo MemberInfo { get; }

        /// <summary>
        /// 实例
        /// </summary>
        public object Instance { get; }

        public string Name { get; set; }

        /// <summary>
        /// label
        /// </summary>
        public string Label { get; set; }

        /// <summary>
        /// value
        /// </summary>
        public object Value { get; set; }

        /// <summary>
        /// 扩展信息
        /// </summary>
        public IDictionary<string, object> Extend { get; set; } = new Dictionary<string, object>();

        /// <summary>
        /// 是否忽略此成员
        /// </summary>
        public bool Ignore { get; set; }
    }
}
